#include <iostream>
#include <string>
#include <memory>
#include <cstdlib>
#include <unistd.h>
#include "inet.hpp"

namespace tcp
{
class tcp_client : public inet::tcp::client
{
public:
    tcp_client(std::string sip, int sport) : inet::tcp::client(sip, sport)
    {}

    void start()
    {
        while (true)
        {
            std::cout << "please input:> ";
            std::string line;
            getline(std::cin, line);

            send(line);

            std::string buf;
            int s = recv(&buf, 1024);
            if (s > 0) buf[s] = 0;
            else continue;

            std::cout << "[server return]" << buf << std::endl;
        }
    }
};
}

int main(int argc, char* argv[])
{
    if (argc != 3)
    {
        printf("Usage error\n");
        exit(1);
    }
    std::string sip = argv[1];
    uint16_t sport = std::stoi(argv[2]);

    std::unique_ptr<tcp::tcp_client> tcli(new tcp::tcp_client(sip, sport));
    tcli->start();

    return 0;
}

